/*	================================================================================
	LinkTracker
	Author: 	Philip Poole
				
	Date:		2009-03-26
	Description:Uses to track non HTML links and links to the shop site in Google Analytics
	================================================================================ */


(function($) {

	/**
	* Will automatically set up Google analytic functions on non HTML files in order
	* to track them.
	* @class
	* @example
	* Call by $.Example.LinkTracker();
	*/
	$.Example.LinkTracker = function() {
		$("	a[href$='.doc'], a[href$='.pdf'], a[href$='.xls'], " +
						"a[href$='.ppt'], a[href$='.mov'], a[href$='.avi'], " +
						"a[href$='.mp3'], a[href$='.mp4']").bind("click", function(e) {
							$.Example.LinkTracker.trackfiles(e);
						});
	};


	/**
	* Will setup URLs with set file extensions to be tracked by Google Anaytics
	* 
	* In order to track what section of the site the files are in, this will be 
	* appended to the tracking URL
	* @param (Object} evt The event when the URL is clicked
	*/
	$.Example.LinkTracker.trackfiles = function(evt) {
		var path = evt.target.href;

		var HOST = "http://" + location.host;
		if (path.match(HOST)) {
			var startPos = HOST.length;
			path = path.substr(startPos, path.length)
		}

		
		alert("Tracked");
		pageTracker._trackPageview(path);
		$.Example.debug("track pdf, path is: ", path);
		

	};

})(jQuery);